
#include <stdio.h>
#include <setjmp.h>
#include "std_header.h"
#include "sci_types.h"
#include "window_parse.h"
#include "mmk_app.h"
#include "guilcd.h"
#include "guilistbox.h"
#include "mmidisplay_data.h"
#include "mmi_menutable.h"
#include "math.h"
#include "float.h"
#include "mmipub.h"
#include "guibutton.h"
#include "mmk_timer.h"
#include "mmi_filemgr.h"
#include "mn_type.h"
#include "sfs.h"
#include "block_mem.h"
#include "mmi_image.h"
#include "lcd_cfg.h"
#include "mmiaudio_ctrl.h"
#include "mmibt_export.h"
#include "mmibt_wintab.h"
#include "mmiudisk_export.h"


#if defined(PLATFORM_SC6800H) || defined(PLATFORM_SC6530)
#define __MY_6800H__
#endif


void toon_ttp1_set_color(GUI_COLOR_T *color, uint8 r, uint8 g, uint8 b)
{
	*color = ((b & 0xf8) >> 3) | ((g & 0xfc) << 3) | ((r & 0xf8) << 8);
}

void toon_ttp1_display_string_by_align(GUI_LCD_DEV_INFO const *dev_info_ptr, 		//ID of LCD to display on
                                     GUI_RECT_T  rect, 		    //the fixed display area
                                     const wchar* str_ptr, 		//string to display
                                     uint16      len, 			//length of string to display
                                     uint16      char_space, 	//space between two chars.
                                     GUI_COLOR_T font_color, 	//string color
                                     GUI_FONT_T  font,	        //font type
                                     GUI_ALIGN_E align,
                                     uint8       line_space       //space between 2 lines
                                     )
{
	/*glp 2011.03.04*/
	#ifndef __MY_6800H__
    LCD_DisplayStringByAlign(dev_info_ptr,
							 rect,
							 str_ptr,
							 len,
							 char_space,
							 font_color,
							 font,
							 align,
							 line_space);
	#else
	MMI_STRING_T    str = {0};
    GUISTR_STYLE_T        str_style = {0};
    GUISTR_STATE_T        str_state = GUISTR_STATE_ALIGN | GUISTR_STATE_WORDBREAK ;//| GUISTR_STATE_SINGLE_LINE

	str.wstr_ptr = str_ptr;
	str.wstr_len = len;

	str_style.font = font;
    str_style.font_color = font_color;
	str_style.line_space = line_space;
    str_style.align = align;
			
	GUISTR_DrawTextToLCDInRect(
						dev_info_ptr,
						&rect,
						&rect,
						&str,//str_ptr,
						&str_style,
						str_state,
						GUISTR_TEXT_DIR_AUTO);

	#endif
}

void toon_ttp1_print_text(int x, int y, char* text, GUI_COLOR_T color)
{
    GUI_POINT_T pos;
    GUI_LCD_DEV_INFO lcd = {GUI_MAIN_LCD_ID, GUI_BLOCK_MAIN};
    char  wide_buf[128];
	GUI_RECT_T  rect;

	if(strlen(text) > 30)
		return;
    pos.x = x;
    pos.y = y;
    TOON_TTP1_ConvertGBKToUnicode(text, (uint16*)wide_buf, sizeof(wide_buf));
	#ifndef __MY_6800H__
    LCD_DisplayString(&lcd, pos, (uint16*)wide_buf, MMIAPICOM_Wstrlen((uint16*)wide_buf), 0, color, SONG_FONT_20, 1);
	#else
	rect.left = x;
	rect.top  = y;
	rect.right = MMI_MAINSCREEN_RIGHT_MAX_PIXEL;
	rect.bottom= y+30;
	toon_ttp1_display_string_by_align(&lcd, 		//ID of LCD to display on
                                 rect, 		    //the fixed display area
                                 (uint16*)wide_buf, 		//string to display
                                 MMIAPICOM_Wstrlen((uint16*)wide_buf), 			//length of string to display
                                 0, 	//space between two chars.
                                 color, 	//string color
                                 SONG_FONT_20,	        //font type
                                 ALIGN_LEFT,
                                 0       //space between 2 lines
                                 );
	#endif
}


void TOON_TTP1_PrintPromptText(int y, char* text)
{
    GUI_LCD_DEV_INFO lcd = {GUI_MAIN_LCD_ID, GUI_BLOCK_MAIN};
    GUI_COLOR_T color;
    GUI_RECT_T  rect;
	
    rect.left   = 0;
	rect.top    = y;
	rect.right  = MMI_MAINSCREEN_RIGHT_MAX_PIXEL;
	rect.bottom = y+20;
	
    LCD_FillRect(&lcd, rect, MMI_WHITE_COLOR);
    //MyTest_FillRect(&lcd, rect, MMI_WHITE_COLOR);
    toon_ttp1_set_color(&color, 0, 0, 0);
    toon_ttp1_print_text(0, y, text, color);

	#if 0
	//not effect!!!
    LCD_InvalidateRect((LCD_ID_E)0,
				0,
				y,
				MMI_MAINSCREEN_RIGHT_MAX_PIXEL,
				y+30);
	#endif
}


